package com.vordel.example.filter.simple;

import com.vordel.circuit.DefaultFilter;
import com.vordel.circuit.FilterConfigureContext;
import com.vordel.circuit.MessageProperties;
import com.vordel.es.EntityStoreException;

/**
 * This object acts as a simple "Addition" Web Service
 * The incoming message is expected to be in the following format:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Add xmlns="http://startvbdotnet.com/web/">
      <a>1</a>
      <b>1</b>
    </Add>
  </soap:Body>
</soap:Envelope>

 The SimpleFilter will contain the local name of the two parameters (i.e. a and b)
 and will also contain the namespace that these elements belong to (i.e. http://startvbdotnet.com/web/)
 */

public class Filter extends DefaultFilter {  
   
    // the element name of the first parameter
    String param1;
    // the namespace of the first element
    String param1Namespace;
    // the element name of the second parameter
    String param2;
    // the namespace of the second paramter
    String param2Namespace;

    protected final void setDefaultProperties() {
        requiredProperties.add(MessageProperties.CONTENT_BODY);
    }
    
    @Override
    public void configure(FilterConfigureContext ctx, com.vordel.es.Entity entity)
        throws EntityStoreException {
        
        super.configure(ctx, entity);
        
        // read the settings for the processor
        param1  = entity.getStringValue("param1");
        param1Namespace  = entity.getStringValue("param1Namespace");
        param2  = entity.getStringValue("param2");
        param2Namespace  = entity.getStringValue("param2Namespace");
    }
 
    public Class<Processor> getMessageProcessorClass() {
        return Processor.class;
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public Class getConfigPanelClass() throws ClassNotFoundException {
        // Avoid any compile or runtime dependencies on SWT and other UI 
        // libraries by lazily loading the class when required.
        return Class.forName(FilterUI.class.getName());
    }
}
